<?php

@include("connect.php");

$uname = $_POST['username'];

$obj = [];

$sql = "SELECT * from cart , goodlist where goodlist.id = cart.goods_id and username = '$uname'";
// 默认只会转第一条数据
$res = mysqli_query($conn, $sql);

$list = [];


while ($data = mysqli_fetch_array($res)) {
    $temp = [];
    $temp['id'] = $data['id'];
    $temp['title'] = $data['title'];
    // $temp['title'] = $data['goods_title'] ;
    // $temp['des'] = $data['goods_des'];
    $temp['img'] = $data['img'];
    $temp['price'] = $data['price'];
    $temp['num'] = $data['num'];
    array_push($list, $temp);
}

if ($list) {
    $obj['status'] = true;
    $obj['msg'] = '数据请求成功';
    $obj['data'] = $list;
} else {
    $obj['status'] = false;
    $obj['msg'] = '购物车为空';
    $obj['data'] = $list;
}

echo (json_encode($obj, JSON_UNESCAPED_UNICODE));
